<template>
  <div class="dialog-container">
    <el-dialog
      v-model="dialogVisible"
      title="Tips"
      width="420"
      :before-close="handleClose"
    >
      <div>
        <SvgIcon :name="icon" :size="iconSize" />
        <p>{{ text }}</p>
      </div>
      <div class="form__footer">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button type="primary" @click="handleSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { defineComponent, computed } from "vue";
export default defineComponent({
  name: "Confirm",
  props: {
    visiable: {
      type: Boolean,
      default: false
    },
    icon: {
      type: String,
      default: "jingshi"
    },
    iconSize: {
      type: Number,
      default: 20
    },
    text: {
      type: String,
      default: "确认删除该条记录吗？"
    }
  },
  emits: ["update:page", "update:limit", "pagination"],
  setup(props, { emit }) {
    const currentPage = computed({
      get() {
        return props.page;
      },
      set(val) {
        emit("update:page", val);
      }
    });
    const pageSize = computed({
      get() {
        return props.limit;
      },
      set(val) {
        emit("update:limit", val);
        // 当改变size时，将页码重置为1，防止请求不到数据
        emit("update:page", 1);
      }
    });
    const handleSizeChange = val => {
      emit("pagination", { page: currentPage, limit: val });
    };
    const handleCurrentChange = val => {
      emit("pagination", { page: val, limit: pageSize });
    };

    return {
      currentPage,
      pageSize,
      handleSizeChange,
      handleCurrentChange
    };
  }
});
</script>

<style lang="scss" scoped>
.pagination-container {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  background: #fff;
  padding: 10px 0;
  .hidden {
    display: none;
  }
  // 分页器icon 图标没对齐，element bug
  & :deep .el-pagination .btn-next .el-icon,
  :deep .el-pagination .btn-prev .el-icon {
    display: unset;
  }
}
</style>
